package com.rs.service.impl.rs;



import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.rs.dao.AttendanceMapper;
import com.rs.dao.AttendanceRulesMapper;
import com.rs.dao.UserMapper;
import com.rs.model.Attendance;
import com.rs.model.AttendanceRules;
import com.rs.model.rs.User;
import com.rs.service.rs.AttendanceSercive;

@Service
public class AttendanceSerciveImpl implements AttendanceSercive {
	@Autowired
	private AttendanceMapper am;
	@Autowired
	private UserMapper um;
	@Autowired
	private AttendanceRulesMapper arDao;
	
	@Override
	public void attendanceAdd1() {
		// TODO Auto-generated method stub
		int at_amtype = 0;
		int at_noontype = 0;
		int at_pmtype = 0;
		int at_nighttype = 0;
		//查看打卡规则
		AttendanceRules ra = arDao.rarSelectAll();
		//为打卡状态赋值
		if(ra.getAtru_am().equals("No clock in")){
			at_amtype = -1;
		}
		if(ra.getAtru_noon().equals("No clock in")){
			at_noontype = -1;
		}
		if(ra.getAtru_pm().equals("No clock in")){
			at_pmtype = -1;
		}
		if(ra.getAtru_night().equals("No clock in")){
			at_nighttype = -1;
		}
		Attendance aa = new Attendance();
		aa.setAt_amtype(at_amtype);
		aa.setAt_noontype(at_noontype);
		aa.setAt_pmtype(at_pmtype);
		aa.setat_nighttype(at_nighttype);
		List<User> ll = um.selectByType();
		List<Attendance> l1 = am.selectByDay();
		if(null!=l1) {
			for(User u1:ll) {
				int uid = u1.getU_id();
				for(Attendance a1:l1){
					int u_id = a1.getAt_uid();
					if(uid==u_id) {
						ll.remove(u1);
					}
				}
			}
		}
		for(User uu:ll) {
			int at_uid = uu.getU_id();
			aa.setAt_uid(at_uid);
			am.attendanceAdd(aa);
		}
		
	}

	@Override
	public void attendanceUpDate(Attendance attendance) {
		// TODO Auto-generated method stub
		am.attendanceUpDate(attendance);
	}

	@Override
	public List<Attendance> attendanceSelectAll() {
		// TODO Auto-generated method stub
		return am.attendanceSelectAll();
	}

	@Override
	public List<Attendance> attendanceSelectByTiaojian(Attendance aa) {
		// TODO Auto-generated method stub
		return am.attendanceSelectByTiaojian(aa);
	}

	
}
